﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace SMSPanasonic.Business
{
    class SmsShortCode
    {
        public string ShortCode { get; set; }
        public string ShortCodeType { get; set; }
        public string MTType { get; set; }
        public bool Enabled { get; set; }
        public int? OrderID { get; set; }

        public SmsShortCode(IDataReader rd)
        {
            this.ShortCode = rd["ShortCode"].ToString();
            this.ShortCodeType = rd["ShortCodeType"].ToString();
            this.MTType = rd["MTType"].ToString();
            this.Enabled = rd["Enabled"].Equals(DBNull.Value) ? false : Convert.ToBoolean(rd["Enabled"]);
            this.OrderID = rd["OrderID"].Equals(DBNull.Value) ? (int?)null : Convert.ToInt32(rd["OrderID"]);
        }
        
        
        public static SmsShortCode GetOne(string shortCode)
        {
            using (SqlDataReader rd = SqlHelper.ExecuteReader(AppConfig.ConnectionString, CommandType.StoredProcedure,
                                "usp_SmsShortCode_GetOne", new SqlParameter("@ShortCode", shortCode)))
            {
                while (rd.Read())
                {
                    return new SmsShortCode(rd);
                }
                return null;
            }
        }

        public static string GetMtType(string shortCode)
        {
            SmsShortCode obj = GetOne(shortCode);
            if (obj != null)
                return obj.MTType;
            return Properties.Settings.Default.DefaultMTType;
        }
    }
}
